//
//  CellForMyExploreTableViewSectionOne.m
//  echo
//
//  Created by dllo on 16/1/29.
//  Copyright © 2016年 Danny. All rights reserved.
//

#define WIDTH [UIScreen mainScreen].bounds.size.width / 414
#define HEIGHT [UIScreen mainScreen].bounds.size.height / 736

#import "CellForMyExploreTableViewSectionOne.h"
#import <SDWebImage/UIButton+WebCache.h>
#import "ModelOfCellForMyExploreTableViewSectionOne.h"
#import "ModelOfCellForMyExploreTableViewSectionOne2.h"
#import "ModelOfCellForMyExploreTableViewSectionOne.h"
#import <DKNightVersion.h>

@implementation CellForMyExploreTableViewSectionOne

- (void)dealloc{
    [_viewOfBack release];
    [_buttonForLeft release];
    [_buttonForRight release];
    [_labelForLeft release];
    [_labelForRight release];
    [_labelForLeftBottom release];
    [_labelForRightBottom release];
    [_arrForDataOfLeft release];
    [_arrForDataOfRight release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.viewOfBack = [[UIView alloc]init];
        [self.contentView addSubview:self.viewOfBack];
        [self.viewOfBack release];
        
        self.buttonForLeft = [UIButton buttonWithType:UIButtonTypeCustom];
        self.buttonForRight = [UIButton buttonWithType:UIButtonTypeCustom];

        
        [self.viewOfBack addSubview:self.buttonForLeft];
        [self.viewOfBack addSubview:self.buttonForRight];
        
        self.labelForLeft = [[UILabel alloc]init];
        [self.viewOfBack addSubview:self.labelForLeft];
        [self.labelForLeft release];
        
        self.labelForRight = [[UILabel alloc]init];
        [self.viewOfBack addSubview:self.labelForRight];
        [self.labelForRight release];
        
        self.labelForLeftBottom = [[UILabel alloc]init];
        [self.viewOfBack addSubview:self.labelForLeftBottom];
        [self.labelForLeftBottom release];
        
        self.labelForRightBottom = [[UILabel alloc]init];
        [self.viewOfBack addSubview:self.labelForRightBottom];
        [self.labelForRightBottom release];
        [self handleNightModel];

    }
    return self;
}

- (void)handleNightModel{
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"夜间模式"]) {
        
        [DKNightVersionManager nightFalling];
        
    } else {
        
        [DKNightVersionManager dawnComing];
    }
    
    self.viewOfBack.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor colorWithRed:17 / 256.f green:27 / 256.f blue:47 / 256.f alpha:1]);
    self.labelForLeft.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    self.labelForLeftBottom.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    self.labelForRight.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    self.labelForRightBottom.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);

    
}

- (void)handleButtonForLeftVideo:(UIButton *)button{
    ModelOfCellForMyExploreTableViewSectionOne *modelForLeft = [[ModelOfCellForMyExploreTableViewSectionOne alloc]init];
    modelForLeft = [self.arrForDataOfLeft objectAtIndex:0];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"postModelForMyExploreVCLeft" object:nil userInfo:@{@"model":modelForLeft}];
}

- (void)handleButtonForRightVideo:(UIButton *)button{
    ModelOfCellForMyExploreTableViewSectionOne *modelForRight = [[ModelOfCellForMyExploreTableViewSectionOne alloc]init];
    modelForRight = [self.arrForDataOfRight objectAtIndex:0];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"postModelForMyExploreVCRight" object:nil userInfo:@{@"model":modelForRight}];
}

//左边视频赋值
- (void)passDataOfCellForTableViewSectionOne:(NSMutableArray *)arr{
    ModelOfCellForMyExploreTableViewSectionOne *modelForLeft = [arr objectAtIndex:0];
    self.arrForDataOfLeft = [NSMutableArray arrayWithArray:arr];
    [self.buttonForLeft sd_setBackgroundImageWithURL:[NSURL URLWithString:modelForLeft.cover_url] forState:UIControlStateNormal];
    self.labelForLeft.text = modelForLeft.name;
    self.labelForLeftBottom.text = modelForLeft.nameForBottom;
    [self.buttonForLeft addTarget:self action:@selector(handleButtonForLeftVideo:) forControlEvents:UIControlEventTouchUpInside];
}

//右边视频赋值
- (void)passDataOfCellForTableViewSectionOne2:(NSMutableArray *)arr{
    ModelOfCellForMyExploreTableViewSectionOne *modelForRight = [arr objectAtIndex:0];
    self.arrForDataOfRight = [NSMutableArray arrayWithArray:arr];
    [self.buttonForRight sd_setBackgroundImageWithURL:[NSURL URLWithString:modelForRight.cover_url] forState:UIControlStateNormal];
    self.labelForRight.text = modelForRight.name;
    self.labelForRightBottom.text = modelForRight.nameForBottom;
    [self.buttonForRight addTarget:self action:@selector(handleButtonForRightVideo:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    self.viewOfBack.frame = self.contentView.frame;

    self.buttonForLeft.frame = CGRectMake(10 * WIDTH, 10 * HEIGHT, (self.contentView.frame.size.width - 30 * WIDTH) / 2, 95 * HEIGHT);
    
    self.buttonForRight.frame = CGRectMake(10 * WIDTH + (self.contentView.frame.size.width - 30 * WIDTH) / 2 + 10 * WIDTH, 10 * HEIGHT, (self.contentView.frame.size.width - 30 * WIDTH) / 2, 95 * HEIGHT);
    
    self.labelForLeft.frame = CGRectMake(10 * WIDTH, 105 * HEIGHT, (self.contentView.frame.size.width - 30 * WIDTH) / 2, 30 * HEIGHT);
    self.labelForLeftBottom.frame = CGRectMake(10 * WIDTH, 135 * HEIGHT, (self.contentView.frame.size.width - 30 * WIDTH) / 2, 20 * HEIGHT);
    
    self.labelForRight.frame = CGRectMake(10 * WIDTH + (self.contentView.frame.size.width - 30 * WIDTH) / 2 + 10 * WIDTH, 105 * HEIGHT, (self.contentView.frame.size.width - 30 * WIDTH) / 2, 30 * HEIGHT);
    self.labelForRightBottom.frame = CGRectMake(10 * WIDTH + (self.contentView.frame.size.width - 30 * WIDTH) / 2 + 10 * WIDTH, 135 * HEIGHT, (self.contentView.frame.size.width - 30 * WIDTH) / 2, 20 * HEIGHT);
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
